﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAWSharp.DSP.EQ;
using DAWSharp.DSP.Dynamics;

namespace DAWSharp.DSP.Delay
{
    public class AnalogDelay : Delay
    {
        private HPF hpf;
        private Saturation sat;
        
        public AnalogDelay(int bufferSize)
        {
            hpf = new HPF(1000.0f, 1.0f, 44100.0f);
            sat = new Saturation();

            bufferSamps = bufferSize;
            delayBuffer = new float[bufferSamps];

            i_pos = 1;
            o_pos = 0;
        }

        new public float Process(float sample, float feedback, int delaySamples)
        {
            float delayOutput = delayBuffer[o_pos];
            delayBuffer[i_pos] = sample + FeedbackChain(delayOutput) * feedback;
            Update(delaySamples);

            return delayOutput;
        }

        private float FeedbackChain(float sample)
        {
            return sat.Process(hpf.Process(sample), 0.3f);
        }
    }
}
